<?php

namespace Model\UserGroupsRoleBundle\Controller;

use Model\RoleBundle\Model\RoleModel;
use Model\UserGroupsBundle\Model\UserGroupsModel;
use Model\UserGroupsRoleBundle\Setting\UserGroupsRoleSetting;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

use Symfony\Component\HttpFoundation\Request;
use Base\BaseController;
use Model\UserGroupsRoleBundle\Entity\UserGroupsRole as Entity;

/**
 * @route("/admin/")
 */
class UserGroupsRoleAdminController extends BaseController
{

    /**
     * @route("UserGroupsRole/add",name="UserGroupsRolePreAdd")
     */
    public function add()
    {
        //通用代码
        $this->setSetting(new UserGroupsRoleSetting($this->getDoctrine()->getManager()));
        return $this->comAdd();
    }

    /**
     * @route("UserGroupsRole/add/do",name="UserGroupsRoleDoAdd")
     *
     * @Method({"GET", "POST"})
     */
    public function doAdd(Request $request)
    {
        //通用代码
        $this->setSetting(new UserGroupsRoleSetting($this->getDoctrine()->getManager()));
        return $this->comDoAdd($request);
    }

    /**
     * @route("UserGroupsRole/edit/{id}",name="UserGroupsRolePreEdit")
     */
    public function edit(Entity $entity)
    {
        $this->setSetting(new UserGroupsRoleSetting($this->getDoctrine()->getManager()));
        return $this->comEdit($entity);
    }

    /**
     * @route("UserGroupsRole/edit/{id}/do",name="UserGroupsRoleDoEdit")
     *
     * @Method({"GET", "POST"})
     */
    public function doEdit(Request $request,Entity $entity)
    {
        $this->setSetting(new UserGroupsRoleSetting($this->getDoctrine()->getManager()));
        return $this->comDoEdit($request,$entity);
    }

    /**
     * @route("UserGroupsRole",name="UserGroupsRoleLists")
     */
    public function lists()
    {
        //私有部分
        $UserGroupsModel = new UserGroupsModel($this->getDoctrine());
        $UserGroups = $UserGroupsModel->getAllUserGroupsTree();
        $RoleModel = new RoleModel($this->getDoctrine());
        $Role = $RoleModel->getAllRoleTree();
        $tools = array(
            "groups"    => $UserGroups,
            "role"    => $Role,
            );

        //通用部分
        $this->setSetting(new UserGroupsRoleSetting($this->getDoctrine()->getManager()));
        return $this->comLists($tools);
    }


    /**
     * @route("UserGroupsRole/tools",name="UserGroupsRoleTools")
     */
    public function tools(Request $request)
    {
        $this->setSetting(new UserGroupsRoleSetting($this->getDoctrine()->getManager()));
        return $this->comTools($request);
    }

}
